function initFetch() {
  function log(...args) {
    // console.log('【重写fetch】', ...args);
  }

  const originFetch = fetch;
  window.fetch = (url, options) => {
    return originFetch(url, options).then(async (response) => {
      try {
        
        function emit(data){
          const customEvent = new CustomEvent('ssePostViewer', {
            detail: data
          });
          window.dispatchEvent(customEvent);
        }

        const contentType = response?.headers?.get('Content-Type') || ''
        if (contentType.includes('text/event-stream')) {
          const responseClone = response.clone();
          const teedOff = responseClone.body.tee();
          const reader = teedOff[1].getReader();
          
          reader.read().then(function processText({ done, value }) {
            if (done) {
              log('读取完毕');
              emit('【DONE】')
              return;
            }
            const decoder = new TextDecoder();
            const text = decoder.decode(value);
            log('读取到数据', text);
            emit(text);
            return reader.read().then(processText);
          });
  
          return response
        } else {
          return response;
        }
      } catch (error) {
        console.error(error)
        return response;
      }
    });
  };
}
initFetch()